package com.qidian.tcba.admin.api.controller;


import com.qidian.tcba.admin.model.dto.systemAdmin.ParkLotOrgDTO;
import com.qidian.tcba.admin.model.dto.systemAdmin.ParkLotOrgManageListDTO;
import com.qidian.tcba.admin.model.query.ParkLotOrgQueryDTO;
import com.qidian.tcba.admin.service.OrgnizationService;
import com.qidian.tcba.utils.JSONResult;
import com.qidian.tcba.utils.Message;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 单位表 前端控制器
 * </p>
 *
 * @author 冯永龙
 * @since 2021-07-06
 */
@RestController
@RequestMapping("/orgnization")
@Api(tags = "单位")
public class OrgnizationController {

    @Autowired
    private OrgnizationService orgnizationService;

    @ApiOperation(notes = "查询停车场单位" ,value = "查询全部所有参数传空")
    @PostMapping ("/getOrgList")
    public JSONResult<List<ParkLotOrgManageListDTO>> getOrgManageList(@RequestBody ParkLotOrgQueryDTO parkLotOrgQueryDTO){
        List<ParkLotOrgManageListDTO> parkLotOrgManageList = orgnizationService.getParkLotOrgManageList(
                parkLotOrgQueryDTO.getDistrictId(),
                parkLotOrgQueryDTO.getName(),
                parkLotOrgQueryDTO.getStatus());
        return new JSONResult<>(parkLotOrgManageList,200,"成功");
    }

    @ApiOperation("新增停车场单位")
    @PostMapping("/add")
    public JSONResult<Object> addOrg(@RequestBody ParkLotOrgDTO parkLotOrgDTO){
        if (orgnizationService.addOrg(parkLotOrgDTO)){
            return new JSONResult<>(null,"成功");
        }else {
            return new JSONResult<>(null, "失败");
        }
    }

    @ApiOperation("修改单位状态")
    @GetMapping("/updateOrgStatus/{status}/{id}")
    public JSONResult<Object> updateOrgStatus(@PathVariable int status, @PathVariable int id){
        if (orgnizationService.updateOrgStatus(status,id)) {
            return new JSONResult<>(null, 200,new Message("DB.UPDATE_SUCCESS","单位"));
        }else {
            return new JSONResult<>(null,200, new Message("DB.UPDATE_FAILED","单位"));
        }
    }
}

